package mx.com.sinformex.simbel.db.eos;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;

import org.apache.tapestry5.beaneditor.NonVisual;

/**
 * @author Oscar Ivan Hernandez Ventura [ oscar at sinformex dot com dot mx]
 *
 * @version $ Id : Group.java , v 1.0 08/05/2009 angellore $
 */

@Entity(name="report_group")
public class Group {
	
	private Integer groupId;
	private String name;
	private String description;
	private List<Report> reports;
	
	@Id
	@Column(name="group_id")
	@GeneratedValue(strategy=GenerationType.AUTO)
	@NonVisual
	public Integer getGroupId() {
		return groupId;
	}
	public void setGroupId(Integer groupId) {
		this.groupId = groupId;
	}
	@Column(nullable=false)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(nullable=false)
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
    @ManyToMany(targetEntity=Report.class,fetch=FetchType.LAZY)
    @JoinTable(name="report_has_group",
            joinColumns=@JoinColumn(name="group_id"),
            inverseJoinColumns=@JoinColumn(name="report_id"))
	public List<Report> getReports() {
    	if(reports == null) {
    		reports = new ArrayList<Report>();
    	}
		return reports;
	}
    public void addToReports(Report report) {
    	if(reports == null) {
    		reports = new ArrayList<Report>();
    	}
    	reports.add(report);
    }
    public boolean haveReport(Report report) {
    	if(reports == null) {
    		reports = new ArrayList<Report>();
    	}
    	return reports.contains(report);
    }
	public void setReports(List<Report> reports) {
		this.reports = reports;
	}
	public final String toString() {
		return String.format("[ Id : %d ; Name : %s]", getGroupId(), getName());
	}
	
}
